<?php
/**
 * 管理员登录界面

 * Author		peace@warmy.cn
 * Version		2.0
 */
include("../config.php");

//如果已经登录则直接跳转到管理页面
if(isset($_SESSION['REEYEE_MANAGE']['userid']))
{
	header("Location: ".ATHENA_SCRIPT_INDEX);
	exit;
}
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
	if(isset($_POST['code']) && isset($_SESSION['checkcode']) && strtolower($_POST['code']) == strtolower($_SESSION['checkcode']))
	{
		unset($_SESSION['WValidate']);
		$db = new WMysql(DB_HOST,DB_USER,DB_PWD,DEBUG);
		$db->select_db(DB_NAME);
		$user = new WUser($db,USERTABLE,'username',"psw",1);
		$user->login('username','pwd');
	}
	else 
	{
		ANotify::halt("验证码不正确！","");
	}
}
if(defined('DEBUG') && DEBUG == 1)
{
	$script = <<< EDN
	$.ajax({
		type:'GET',
		url:'/include/getCode.php?rnd'+Math.random(),
		dataType:'text',
		success:function(msg){
			document.frmlogin.code.value = msg;
		}
	});
EDN;
	
}
else 
	$script = '';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?=CHARSET?>" />
<title><?=MANAGE_TITLE?></title>
<script type="text/javascript" src="js/std.js"></script>
<script type="text/javascript" src="/script/jquery-1.4.2.min.js"></script>
<link rel="stylesheet" type="text/css" href="css/style.css"/>
</head>
<body>
<script type="text/javascript">
function CheckForm(frm)
{
    try
    {
        if(!CheckTextB(frm.username,8,"请输入用户名！"))
            return false;
        if(!CheckTextB(frm.pwd,8,"请输入密码！"))
            return false;
        if(!CheckTextB(frm.code,8,"请输入验证码！"))
            return false;
        frm.submit();
    }
    catch(e)
    {
        alert(e.description);
    }
    return false;
}
$(document).ready(function(){
	<?php echo $script;?>
	$("#getcode").click(function(){
		document.frmlogin.code.value = '';
		$(this).attr("src","/include/checkcode.php?rnd"+Math.random());
	})
})
</script>
<style type="text/css">body{background:#161616 url(css/images/loginBg.gif) no-repeat center center }</style>
<table border="0" cellspacing="0" cellpadding="0" align="center" class="login" >
  <form  method="post" name="frmlogin" id="frmlogin" onsubmit="return CheckForm(this);">
    <tr>
      <td class="loginLeft"></td>
      
      <td class="loginMid" valign="top"><table width="86%" border="0" cellspacing="0" cellpadding="0" align="center" >
        <tr>
          <td colspan="4" class="loginTitle">&nbsp;</td>
        </tr>
        <tr>
          <td colspan="4" class="loginWel"></td>
        </tr>
        <tr>
          <td  align="left" height="30">用户名：</td>
          <td><input type="text" name="username" value="<?=defined('DEBUG') && DEBUG == 1?'reeyee':''?>" /></td>
          <td >密码：</td>
          <td align="left"><input type="password" name="pwd" value="<?=defined('DEBUG') && DEBUG == 1?'123456':''?>" /></td>
        </tr>
        <tr>
          <td  align="left">验证码：</td>
          <td><input type="text" name="code" value=""/></td>
          <td align="left" colspan="2"><img src="/include/checkcode.php" id="getcode" alt="看不清楚，重新换一张" style="cursor:hand;"/></td>
        </tr>
         <tr>
          <td colspan="4" align="right" valign="bottom" height="50"><input name="submitimg" type="image" src="css/images/login.gif" class="image"/>
          <input type="hidden" name="dosubmit" value="提交" >
          </td>
        </tr>
      </table></td>
      <td class="loginRight"></td>
    </tr>
  </form>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="bottom">
  <tr>
    <td class="br"><span></span>&copy; Copyright  2005-2008  <a href="http://www.reeyee.cn" target="_blank">reeyee</a>  allrights revered.</td>
  </tr>
</table>
</body>
</html>